package com.ruoyi.ws.facade;


import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.AdminPreid;
import com.ruoyi.system.service.IAdminPreidService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * 课时相关接口
 *
 * @author roytrack
 * @date 2020-05-25 17:37:24
 */
@RestController
@RequestMapping(path = "services/preid")
public class PreidResource {

  /**
   * LOGGER
   */
  private static final Logger LOGGER = LoggerFactory.getLogger(PreidResource.class);
  @Autowired
  private IAdminPreidService adminPreidService;

  /**
   * 根据课程查询课时
   * @param subjectId
   * @return
   */
  @PostMapping("/getPreidBySubjectId")
  @ResponseBody
  public AjaxResult getPreidBySubjectId (Long subjectId) {
    try {
      AdminPreid adminPreid  = new AdminPreid();
      adminPreid.setSubjectId(subjectId);
      List<AdminPreid> adminPreidList = adminPreidService.selectAdminPreidList(adminPreid);
      return success(adminPreidList);
    } catch (Exception e) {
      LOGGER.info("根据课程查询课时失败",e);
      return error("根据课程查询课时失败");
    }
  }

}
